Skip to content

fix: match Angular for safe-read guard temporaries and temp order - #739

Merged
Brooooooklyn merged 3 commits into
mainfrom
fix/temp-followups
Nov 25, 2026
Merged

Brooooooklyn merged 3 commits into
mainfrom
fix/temp-followups

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Follow-ups found while working on #737.

1. Safe-read guard ran calls twice

template:  {{ f1()?.[f2()?.a]?.b }}   (legacy optional chaining)

before:  tmp_0[(tmp_1 = ctx.f2()) == null ? null : tmp_1.a] == null ? null
       : tmp_0[(tmp_1 = ctx.f2()) == null ? null : tmp_1.a].b      ← f2() called again
after:   ...
       : tmp_0[(tmp_1 = tmp_1) == null ? null : tmp_1.a].b         ← reads it back

When the guard is copied into the body, Angular's eliminateTemporaryAssignments turns tmp = expr into tmp = tmp. We copied the guard as is, so every call in it ran twice. Output now matches Angular's own compliance file safe_access_temporaries_template_use_null.js.

Arrow functions inside the guard are skipped, because they are their own scope. Angular walks into them too, but then fails with "Found xref with unassigned name". Main's output for those stays the same.

2. Temp declarations sorted as strings

With 11+ temps in one op we declared tmp_0_10 before tmp_0_2. Now they keep the order they were first assigned, like Angular's new Set(defs.values()). That is always number order.

3. One shared is_js_whitespace

transform/boundaries.rs now uses the helper from util/chars.rs instead of its own copy. No behaviour change.

Checks

Check Result
Temp names and assignments vs real ngc 22.3.0, 86 nested safe-call templates main 31/86, this PR 84/86 (the other 2 differ only by Angular's /* @ts-ignore */ comment in @for track)
Output vs main, 1198 files × 4 option sets same, except the 2 safe_access_temporaries compliance files, now as Angular expects
~450 extra templates from #737 same as main, except nested safe-call cases, which all match ngc
cargo test --all-features 4248 passed
conformance no change

Not fixed here (older, separate)

  • Inside an arrow function, every temp gets the name _tmp, so a nested safe call can overwrite a value that is still needed. Angular refuses such templates ("Assign of unnamed temporary").
  • Very deep nested safe calls (about 11 levels) overflow the default 2 MB test thread stack in debug builds, on main too. Release builds are fine. The new test runs on a bigger stack.

🤖 Generated with Claude Code

Brooooooklyn and others added 3 commits November 25, 2026 21:13
…g again

When a safe access copies a guard that has no temporary of its own, the
copy re-ran every expression the guard had stored in a temporary, e.g.
`(tmp_0_1 = ctx.f2())` twice, so calls and their side effects ran twice.
Port Angular's eliminateTemporaryAssignments: in the copy, `tmp = expr`
becomes `tmp = tmp`. Output now matches Angular's compliance file
safe_access_temporaries_template_use_null.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The declarations were sorted as strings, so with 11 or more temporaries
in one op `tmp_0_10` came before `tmp_0_2`. Keep the order the names
were first assigned, like Angular's `new Set(defs.values())`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T13:17:58.724030Z 66d1d2a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 66d1d2a811

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit ff954a3 into main Nov 25, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/temp-followups branch November 25, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant